﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LogException
{
    /// <summary>
    /// 线程异常处理类
    /// </summary>
    public class AppThreadException 
    {
        /// <summary>
        /// 处理线程异常：记录线程异常但不结束当前线程
        /// </summary>
        /// <param name="ex"></param>
        public AppThreadException(Exception ex)
        {
            new WorkerThreadExceptionHandlerDelegate(WorkerThreadExceptionHandler).BeginInvoke(ex, null, null);
        }

        #region 线程异常处理过程
        /// <summary>
        /// 工作线程捕获委托
        /// </summary>
        /// <param name="ex"></param>
        public delegate void WorkerThreadExceptionHandlerDelegate(Exception ex);

        /// <summary>
        /// 工作线程错误捕获处理函数
        /// </summary>
        public void WorkerThreadExceptionHandler(Exception ex)
        {
            AppException.UnhandledException(this, new System.Threading.ThreadExceptionEventArgs(ex));
        }
        #endregion
    }
}
